Skip to content

more proper dbstring memory management#506

Closed
fluxide wants to merge 2 commits into
EasyRPG:masterfrom
fluxide:master
Closed

more proper dbstring memory management#506
fluxide wants to merge 2 commits into
EasyRPG:masterfrom
fluxide:master

Conversation

@fluxide
Copy link
Copy Markdown

@fluxide fluxide commented Feb 13, 2026

on windows, i was getting assertion errors from dbarrayalloc.h months ago when it was struggling with memory management. i have identified that empty_buf() is supposed to return two consequent memory addresses that are supposed to mimick a dbstring structure; however, the existing method seemed to be fragile on windows, so i cleaned it up a little bit. it doesnt seem to show undefined behavior anymore.

fluxide added 2 commits August 5, 2025 02:37
empty_buf function returns a char* now, and the free function in dbarray uses the get_size_ptr function to detect uninitialized void* objects
-identified the problem with heap allocation in dbstrings
-empty_buf() now returns 2 bytes, properly mimicking the void* structure of a dbstring.
@fluxide
Copy link
Copy Markdown
Author

fluxide commented Feb 13, 2026

i made one of my commits to my branch 3 months ago. admittedly i dont remember what i changed but if it looks weird feel free to correct anything

@Ghabry
Copy link
Copy Markdown
Member

Ghabry commented May 1, 2026

Honestly I'm not sure how this change is supposed to work.

I'll close it and ask you to create an issue with a test case that triggers the memory problem for you.


Problematic changes:

_empty_buf is now an uint16_t so _empty_buf + 1 will read out of bounds.

(void*)(&_empty_buf + 1);

This is simply leaking memory as the raw is overwritten on the next line:

void* raw = new void*;

Compiler warning:

dbarray.cpp:60:24: Warning: Deleting »void*« is undefined [-Wdelete-incomplete]

Linker error:

FAILED: [code=1] lcf2xml 
: && /usr/bin/c++ -Wall -Wextra -fsanitize=address,undefined -g -Wl,--dependency-file=CMakeFiles/lcf2xml.dir/link.d CMakeFiles/lcf2xml.dir/tools/lcf2xml.cpp.o -o lcf2xml  liblcfd.a  /usr/lib/libinih.so  /usr/lib/libicui18n.so  /usr/lib/libicuuc.so  -ldl  /usr/lib/libicudata.so  /usr/lib/libexpat.so.1.11.3  -lm && :
/usr/bin/ld: CMakeFiles/lcf2xml.dir/tools/lcf2xml.cpp.o: warning: relocation against `_ZN3lcf12DBArrayAlloc10_empty_bufE' in read-only section `.text._ZN3lcf12DBArrayAlloc9empty_bufEv[_ZN3lcf12DBArrayAlloc9empty_bufEv]'
/usr/bin/ld: CMakeFiles/lcf2xml.dir/tools/lcf2xml.cpp.o: in function `lcf::DBArrayAlloc::empty_buf()':
/tmp/liblcf/src/lcf/dbarrayalloc.h:31:(.text._ZN3lcf12DBArrayAlloc9empty_bufEv[_ZN3lcf12DBArrayAlloc9empty_bufEv]+0x7): undefined reference to `lcf::DBArrayAlloc::_empty_buf'
/usr/bin/ld: /tmp/liblcf/src/lcf/dbarrayalloc.h:31:(.text._ZN3lcf12DBArrayAlloc9empty_bufEv[_ZN3lcf12DBArrayAlloc9empty_bufEv]+0x18): undefined reference to `lcf::DBArrayAlloc::_empty_buf'
/usr/bin/ld: /tmp/liblcf/src/lcf/dbarrayalloc.h:31:(.text._ZN3lcf12DBArrayAlloc9empty_bufEv[_ZN3lcf12DBArrayAlloc9empty_bufEv]+0x31): undefined reference to `lcf::DBArrayAlloc::_empty_buf'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: Fehler: ld gab 1 als Ende-Status zurück
[161/161] Linking CXX executable lcfstrings

@Ghabry Ghabry closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants